package gui2.g4;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class ChatTableModel extends AbstractTableModel implements
		ChatModelListener {

	@Override
	public int getRowCount() {
		return messages.size();
	}

	@Override
	public int getColumnCount() {
		return 2;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		ChatMessage m = messages.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return m.getUsername();
		case 1:
			return m.getMsg();
		default:
			return null;
		}
	}

	@Override
	public void messageAdded(List<ChatMessage> allMessages) {
		messages = allMessages;
		fireTableDataChanged();
	}

	private List<ChatMessage> messages = new ArrayList<ChatMessage>();

}
